const sequelize = require('../db/seq.js')

const User = require('./user_model.js')
const User_like = require('./User_Likes')
const Friendship = require('./friend_model.js')
const Chat = require('./Chat_model.js')

User.hasMany(User_like, { foreignKey: 'user_id' })
User_like.belongsTo(User, { foreignKey: 'user_id' })


User.belongsToMany(User, {
    through: Friendship, // 使用 Friendship 表作为中间表
    as: 'Friends', // 别名，用于查询好友
    foreignKey: 'userId', // 发起方的外键
    otherKey: 'friendId', // 好友方的外键
});

User.hasMany(Chat, { foreignKey: 'senderId', as: 'SentMessages' });
User.hasMany(Chat, { foreignKey: 'receiverId', as: 'ReceivedMessages' });
Chat.belongsTo(User, { foreignKey: 'senderId', as: 'Sender' });
Chat.belongsTo(User, { foreignKey: 'receiverId', as: 'Receiver' });

// sequelize.sync({ force: false })
